/*
*  Copyright 2020-2021 Li Fei
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.pengshun.modules.api.coal.service.dto;
import com.fasterxml.jackson.annotation.JsonView;
import com.pengshun.modules.api.coal.domain.enums.CoalInfoEnum;
import com.pengshun.modules.api.coal.domain.enums.UnitEnum;
import com.pengshun.modules.common.ReslutView;
import lombok.Data;
import java.io.Serializable;

/**
* @description /
* @author lifei
* @date 2020-11-13
**/
@Data
public class MerchantCoalInfoDto implements Serializable {

    /** 商户煤炭属性id */
    private Long id;

    /** 商户煤炭id */
    private Long merchantCoalId;

    /** 名称 */
    @JsonView(ReslutView.bView.class)
    private String coalName;


    /** key唯一编码 */
    @JsonView(ReslutView.bView.class)
    private String categoryKey;

    /** 值 */
    @JsonView(ReslutView.bView.class)
    private String value;

    public MerchantCoalInfoDto(Long merchantCoalId, String coalName, String categoryKey, String value) {
        this.merchantCoalId = merchantCoalId;
        this.coalName = coalName;
        this.categoryKey = categoryKey;
        this.value = value;
    }

    @JsonView(ReslutView.bView.class)
    private String unit;

    public String getUnit() {
        String units=unit;
        if(this.categoryKey!=null){
            if(this.categoryKey.equals(CoalInfoEnum.HIGH_ORDER.getKey())||this.categoryKey.equals(CoalInfoEnum.LOW_ORDER.getKey())){
                units= UnitEnum.KILOGRAM.getKey();
            }else {
                units= UnitEnum.PERCENT.getKey();
                if(this.categoryKey.equals(CoalInfoEnum.CRC.getKey())){
                    units=null;
                }
            }
        }
        return units==null?"":units;
    }

    public MerchantCoalInfoDto() {
    }

    public MerchantCoalInfoDto(String coalName, String value, String unit) {
        this.coalName = coalName;
        this.value = value;
        this.unit = unit;
    }
//    public String getValue() {
//        return value==null?"0":value;
//    }
}